#include "Point3D.h"
#include <math.h>

Point3D::Point3D( void ):x(0),y(0),z(0)
{
	
}

Point3D::Point3D( float x1, float y1, float z1 ):x(x1),y(y1),z(z1)
{

}

Point3D::Point3D( glm::vec3 v1 )
{
	x = v1[0];
	y = v1[1];
	z = v1[2];
}


Point3D::~Point3D(void)
{
}

float Point3D::length()
{
	return sqrt(x*x+y*y+z*z);
}

Point3D Point3D::normalize()
{
	float l = length();
	if(l == 0)
		return Point3D(0,0,0);
	else
		return Point3D(x/l,y/l,z/l);
}

Point3D Point3D::operator+( Point3D p1 )
{
	return Point3D(x+p1.x,y+p1.y,z+p1.z);
}

Point3D Point3D::operator-( Point3D p1)
{
	return Point3D(x-p1.x,y-p1.y,z-p1.z);
}

Point3D Point3D::operator*( float a1 )
{
	return Point3D(x*a1,y*a1,z*a1);
}

Point3D Point3D::operator/( float a1 )
{
	return Point3D(x/a1,y/a1,z/a1);
}

Point3D Point3D::crossProduct( Point3D p1)
{
	return Point3D(y*p1.z - z*p1.y,z*p1.x - x*p1.z,x*p1.y - y*p1.x);
}

float Point3D::dotProduct( Point3D p1 )
{
	return x*p1.x+y*p1.y+z*p1.z;
}

Point3D Point3D::operator=( Point3D p1 )
{
	x = p1.x;
	y = p1.y;
	z = p1.z;
	return *this;
}

Point3D& Point3D::operator+=( Point3D p1 )
{
	x += p1.x;
	y += p1.y;
	z += p1.z;
	return *this;
}

Point3D Point3D::scale( Point3D p )
{
	Point3D result = Point3D(x /= p.x,y /= p.y, z /= p.z);
	if(p.x == 0)
		result.x = 0;
	if(p.y == 0)
		result.y = 0;
	if(p.z == 0)
		result.z = 0;
	return result;
}

Point3D Point3D::operator-()
{
	return Point3D(-x,-y,-z);
}

Point3D abs( Point3D p )
{
	p.x = abs(p.x);
	p.y = abs(p.y);
	p.z = abs(p.z);
	return p;
}
